package com.braveman.im.ui.activity.message;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.braveman.im.R;
import com.braveman.im.bean.SendNoticeBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

import retrofit2.Call;
import retrofit2.Response;


public class SendCompanyNotifyActivity extends BaseActivity {
    private String groupId;
    private String groupType;
    private EditText mEtActivitySendNoticeSub;
    private EditText mEtActivitySendNoticeDetails;


    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("发布公告").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtils.finishActivity(SendCompanyNotifyActivity.this);
            }
        });
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_send_compand_notify;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        groupId = callIntent.getStringExtra("groupId");
        groupType = callIntent.getStringExtra("groupType");
    }

    @Override
    protected void initChildView() {
        mEtActivitySendNoticeSub = (EditText) findViewById(R.id.et_activity_send_notice_sub);
        mEtActivitySendNoticeDetails = (EditText) findViewById(R.id.et_activity_send_notice_details);

    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        findViewById(R.id.btn_activity_register).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_activity_register:
                doNetWork();
                break;
        }
    }

    private void doNetWork() {
        String subject = mEtActivitySendNoticeSub.getText().toString().trim();
        String detail = mEtActivitySendNoticeDetails.getText().toString().trim();
        if (TextUtils.isEmpty(subject)) {
            UIUtils.showToast("公告主题不能为空");
            return;
        }

        if (TextUtils.isEmpty(detail)) {
            UIUtils.showToast("公告详情不能为空");
            return;
        }

        SendNoticeBean sendNoticeBean = new SendNoticeBean();
        sendNoticeBean.groupId = groupId;
//        "company", "individual", "plateform",
        sendNoticeBean.groupType = TextUtils.isEmpty(groupType) ? "individual" : groupType;
        sendNoticeBean.subject = subject;
        sendNoticeBean.detail = detail;


        showLoadingDialog();
        ApiManager.getApi().sendGroupNotice(sendNoticeBean).enqueue(new NetCallBack<SendNoticeBean>() {
            @Override
            protected void onSuccess(Call<SendNoticeBean> call, Response<SendNoticeBean> response) {
                if (response != null) {
                    UIUtils.showToast("'发布成功'");
                    ActivityUtils.finishActivity(SendCompanyNotifyActivity.this);
                }
            }

            @Override
            protected void hiddenProgress() {
                hideLodingDialog();
            }
        });
    }

}
